/** Get Location Information **/
package com.HelpDog.src;

import java.util.ArrayList;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationProvider;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public class LoListener implements LocationListener {
	Location loc;
	ArrayList<MyPoint> pointList;
	HelpDogActivity mHelpDogActivity;
	
	LoListener(Context context) {
		pointList = new ArrayList<MyPoint>();
		this.mHelpDogActivity = (HelpDogActivity)context;
	}

	/** If Changed Location **/
	public void onLocationChanged(Location location) {
		loc = location;
		double lat = loc.getLatitude();
		double lng = loc.getLongitude();
		MyPoint p = new MyPoint((int)(lat*1000000), (int)(lng*1000000));
		
		Message msg = new Message();
		msg.what = 0;
		msg.obj = p;
		handler.sendMessage(msg);
	}
	
	private Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			switch(msg.what) {
			case 0 :
				mHelpDogActivity.addCoordinate((MyPoint)msg.obj);
				break;
			}
		}
	};

	/** If Can't Getting Location Information **/
	public void onProviderDisabled(String provider) {
		// TODO
	}

	/** If Can Getting Location Information **/
	public void onProviderEnabled(String provider) {
		// TODO
	}

	/** If Status Changed **/
	public void onStatusChanged(String provider, int status, Bundle extras) {
		switch (status) {
		case LocationProvider.OUT_OF_SERVICE:
			// TODO
			break;
		case LocationProvider.TEMPORARILY_UNAVAILABLE:
			// TODO
			break;
		case LocationProvider.AVAILABLE:
			// TODO
			break;
		}

	}
}
